home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / fmxwin.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  10.8 KB  |  298 lines

  1. //----------------------------------------------------------------------------
  2. //Borland C++Builder
  3. //Copyright (c) 1987, 1998 Borland International Inc. All Rights Reserved.
  4. //----------------------------------------------------------------------------
  5. //---------------------------------------------------------------------------
  6. #include <vcl.h>
  7. #pragma hdrstop
  8. #include <ctype.h>
  9. #include <process.h>
  10. #include <stdio.h>
  11. #include "fmxUtils.h"
  12. #include "FAttrdlg.h"
  13. #include "fchngdlg.h"
  14. #include "fmxwin.h"
  15. //---------------------------------------------------------------------------
  16. #pragma link "CDIROUTL"
  17. #pragma link "cdiroutl"
  18. #pragma resource "*.dfm"
  19. TFormMain *FormMain;
  20. //---------------------------------------------------------------------------
  21. __fastcall TFormMain::TFormMain(TComponent* Owner)
  22.     : TForm(Owner)
  23. {
  24. }
  25. //---------------------------------------------------------------------------
  26. void __fastcall TFormMain::Exit1Click(TObject *Sender)
  27. {
  28.   Close();
  29. }
  30. //---------------------------------------------------------------------
  31. #pragma warn -sig
  32. void __fastcall TFormMain::Properties1Click(TObject *Sender)
  33. {
  34.  
  35.   unsigned short  Attributes;
  36.   unsigned short  NewAttributes;
  37.  
  38.   FileAttrDlg->FileDirName->Caption = FileList->Items->Strings[FileList->ItemIndex];
  39.   FileAttrDlg->FilePathName->Caption = FileList->Directory;
  40.   FileAttrDlg->ChangeDate->Caption = DateTimeToStr(FileDateTime(FileList->FileName));
  41.   Attributes = FileGetAttr(FileList->Items->Strings[FileList->ItemIndex]);
  42.   FileAttrDlg->ReadOnly->Checked = Attributes & faReadOnly;
  43.   FileAttrDlg->Archive->Checked = Attributes & faArchive;
  44.   FileAttrDlg->System->Checked = Attributes & faSysFile;
  45.   FileAttrDlg->Hidden->Checked = Attributes & faHidden;
  46.   if (FileAttrDlg->ShowModal()!= mrCancel){
  47.      NewAttributes = Attributes;
  48.      if (FileAttrDlg->ReadOnly->Checked)
  49.        NewAttributes = NewAttributes | faReadOnly;
  50.      else
  51.         NewAttributes = NewAttributes & ~faReadOnly;
  52.  
  53.      if (FileAttrDlg->Archive->Checked)
  54.        NewAttributes = NewAttributes | faArchive;
  55.      else
  56.        NewAttributes = NewAttributes & ~faArchive;
  57.  
  58.      if (FileAttrDlg->System->Checked)
  59.        NewAttributes = NewAttributes | faSysFile;
  60.      else
  61.        NewAttributes = NewAttributes & ~faSysFile;
  62.  
  63.      if (FileAttrDlg->Hidden->Checked)
  64.        NewAttributes = NewAttributes | faHidden;
  65.      else
  66.        NewAttributes = NewAttributes  & ~faHidden;
  67.      if (NewAttributes != Attributes)
  68.        FileSetAttr(FileAttrDlg->FileDirName->Caption, NewAttributes);
  69.   }
  70. }
  71. #pragma warn .sig
  72.  
  73. //---------------------------------------------------------------------
  74. void __fastcall TFormMain::DirectoryOutlineChange(TObject *Sender)
  75. {
  76.   FileList->Directory = DirectoryOutline->Directory;
  77.   DirectoryPanel->Caption=DirectoryOutline->Directory;
  78. }
  79. //---------------------------------------------------------------------
  80. void __fastcall TFormMain::DirectoryOutlineDragDrop(TObject *Sender,
  81.                                                     TObject *Source,
  82.                                                     int X, int Y)
  83. {
  84.   if (dynamic_cast<TFileListBox *> (Source)!=0)
  85.     ConfirmChange("Move", FileList->FileName,
  86.     DirectoryOutline ->Items[DirectoryOutline ->GetItem(X, Y)]->FullPath);
  87. }
  88. //---------------------------------------------------------------------
  89. void __fastcall TFormMain::DirectoryOutlineDragOver(TObject *Sender,
  90.                                                     TObject *Source,
  91.                                                     int X, int Y,
  92.                                                     TDragState State,
  93.                                                     bool &Accept)
  94. {
  95.   if (dynamic_cast<TFileListBox *> (Source))
  96.       Accept = True;
  97. }
  98.  
  99. //---------------------------------------------------------------------
  100. #pragma warn -stv
  101. void __fastcall TFormMain::ConfirmChange(const AnsiString ACaption,
  102.                                          AnsiString FromFile,
  103.                                          AnsiString ToFile)
  104. {
  105.   char buffer[700];
  106.   sprintf(buffer,"%s %s to %s?",ACaption, FromFile, ToFile);
  107.   if(MessageDlg(buffer,
  108.                 mtConfirmation,
  109.                 TMsgDlgButtons() << mbYes << mbNo,
  110.                 0) == mrYes){
  111.       {
  112.         if (ACaption == "Move")
  113.           MoveFile(FromFile, ToFile);
  114.         else if (ACaption == "Copy")
  115.           CopyFile(FromFile, ToFile);
  116.         else if (ACaption =="Rename")
  117.           RenameFile(FromFile, ToFile);
  118.       }
  119.      FileList->Update();
  120.    }
  121. }
  122. #pragma warn .stv
  123.  
  124. //---------------------------------------------------------------------
  125. void __fastcall TFormMain::FormCreate(TObject *Sender)
  126. {
  127.   static char * Drive_Letter[]={"a:\\","b:\\","c:\\","d:\\","e:\\","f:\\",
  128.       "g:\\","h:\\","i:\\","j:\\","k:\\","l:\\","m:\\","n:\\","o:\\","p:\\",
  129.       "q:\\","r:\\","s:\\","t:\\","u:\\","v:\\","w:\\","x:\\","y:\\","z:\\"};
  130.  
  131.   int  AddedIndex;
  132.      for(int x =0; x <= 25; x++ )
  133.       {
  134.         switch(GetDriveType(Drive_Letter[x]))
  135.           {
  136.               case DRIVE_REMOVABLE:
  137.                 AddedIndex=DriveTabSet->Tabs->AddObject(String(Drive_Letter[x]),
  138.                 Floppy->Picture->Graphic);
  139.               break;
  140.               case DRIVE_FIXED:
  141.                 AddedIndex=DriveTabSet->Tabs->AddObject(String(Drive_Letter[x]),
  142.                 Fixed->Picture->Graphic);
  143.               break;
  144.               case DRIVE_REMOTE:
  145.                 AddedIndex=DriveTabSet->Tabs->AddObject(String(Drive_Letter[x]),
  146.                 Network->Picture->Graphic);
  147.               break;
  148.               case DRIVE_CDROM:
  149.                 AddedIndex=DriveTabSet->Tabs->AddObject(Drive_Letter[x],
  150.                 Floppy->Picture->Graphic);
  151.               break;
  152.               case DRIVE_RAMDISK:
  153.                 AddedIndex=DriveTabSet->Tabs->AddObject(Drive_Letter[x],
  154.                 Floppy->Picture->Graphic);
  155.               break;
  156.             }
  157.  
  158.           if (toupper(*Drive_Letter[x]) == FileList->Drive)
  159.               DriveTabSet->TabIndex = AddedIndex;
  160.  
  161.        }
  162. }
  163.  
  164. //---------------------------------------------------------------------
  165. #pragma warn -stv
  166. void __fastcall TFormMain::FileListChange(TObject *Sender)
  167. {
  168.   AnsiString TheFileName;
  169.     if(FileList->ItemIndex>=0){
  170.         char buffer[255];
  171.         TheFileName =FileList->Items->Strings[FileList->ItemIndex];
  172.         sprintf(buffer,
  173.                 "%s  %d bytes",
  174.                 TheFileName,
  175.                 GetFileSize(TheFileName));
  176.         FilePanel->Caption = buffer;
  177.  
  178.         if (GetFileAttributes(TheFileName.c_str()) & FILE_ATTRIBUTE_DIRECTORY)
  179.           FileSelected = false;
  180.         else
  181.           FileSelected = true;
  182.     }
  183.     else {
  184.          FilePanel->Caption="";
  185.          FileSelected = false;
  186.     }
  187. }
  188. #pragma warn .stv
  189.  
  190. //---------------------------------------------------------------------
  191. void __fastcall TFormMain::FileListEndDrag(TObject *Sender,TObject *Target,
  192.                                            Integer X, Integer Y)
  193.  
  194. {
  195.    if (Target != NULL)
  196.    FileList->Update();
  197. }
  198. //---------------------------------------------------------------------
  199. void __fastcall TFormMain::FileListMouseDown(TObject *Sender,
  200.      TMouseButton Button, TShiftState Shift, Integer X, Integer Y)
  201. {
  202.   if(Button==mbLeft)
  203.     {
  204.       if (dynamic_cast<TFileListBox *>(Sender)!=0)
  205.            {
  206.              if(dynamic_cast<TFileListBox *>(Sender)->ItemAtPos(Point(X,Y),
  207.                             True) >=0)
  208.               dynamic_cast<TFileListBox *>(Sender)->BeginDrag(False);
  209.            }
  210.     }
  211. }
  212. //---------------------------------------------------------------------
  213. void __fastcall TFormMain::DriveTabSetClick(TObject *Sender)
  214. {
  215.   DirectoryOutline->Drive= *((DriveTabSet->Tabs->Strings
  216.                              [DriveTabSet->TabIndex]).c_str());
  217. }
  218. //---------------------------------------------------------------------
  219. void __fastcall TFormMain::DriveTabSetDrawTab(TObject *Sender,
  220.                                               TCanvas *TabCanvas,
  221.                                               TRect &R, Integer Index,
  222.                                               Boolean Selected)
  223. {
  224.   Graphics::TBitmap *Bitmap;
  225.   Bitmap = (Graphics::TBitmap *) (DriveTabSet->Tabs->Objects[Index]);
  226.   TabCanvas->Draw(R.Left, R.Top + 4, Bitmap);
  227.   TabCanvas->TextOut(R.Left + 2 + Bitmap->Width, R.Top + 2,
  228.               DriveTabSet->Tabs->Strings[Index].SubString(1,1));
  229.  
  230. }
  231. //---------------------------------------------------------------------
  232. void __fastcall TFormMain::DriveTabSetMeasureTab(TObject *Sender,
  233.                  Integer Index, Integer &TabWidth)
  234. {
  235.   int BitmapWidth;
  236.   BitmapWidth = ((Graphics::TBitmap *)
  237.                 (DriveTabSet->Tabs->Objects[Index]))->Width;
  238.   TabWidth=TabWidth+2+BitmapWidth;
  239. }
  240. //---------------------------------------------------------------------
  241. void __fastcall TFormMain::File1Click(TObject *Sender)
  242. {
  243.     Open1->Enabled = FileSelected;
  244.     Delete1->Enabled = FileSelected;
  245.     Copy1->Enabled = FileSelected;
  246.     Move1->Enabled = FileSelected;
  247.     Rename1->Enabled = FileSelected;
  248.     Properties1->Enabled = FileSelected;
  249. }
  250. //---------------------------------------------------------------------
  251. void __fastcall TFormMain::Delete1Click(TObject *Sender)
  252. {
  253.   if(MessageDlg("Delete" + FileList->FileName + "?",
  254.                 mtConfirmation,
  255.                 TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes){
  256.     if(DeleteFile(FileList->FileName.c_str()))
  257.       FileList->Items->Delete(FileList->ItemIndex);
  258.   }
  259. }
  260. //---------------------------------------------------------------------
  261. void __fastcall TFormMain::Open1Click(TObject *Sender)
  262. {
  263.   if (HasAttr(FileList->FileName, faDirectory))
  264.     DirectoryOutline->Directory = FileList->FileName;
  265.   else
  266.     ExecuteFile(FileList->FileName," ", DirectoryOutline->Directory, SW_SHOW);
  267.  }
  268. //---------------------------------------------------------------------
  269. void __fastcall TFormMain::FileChange(TObject *Sender)
  270. {
  271.   if (dynamic_cast<TMenuItem *>(Sender) == Move1 )
  272.     ChangeDlg->Caption = "Move" ;
  273.   else if (dynamic_cast<TMenuItem *>(Sender) == Copy1)
  274.     ChangeDlg->Caption = "Copy";
  275.   else if (dynamic_cast<TMenuItem *>(Sender) == Rename1)
  276.     ChangeDlg->Caption = "Rename";
  277.   else
  278.     _c_exit();
  279.  
  280.   ChangeDlg->CurrentDir->Caption = DirectoryOutline->Directory;
  281.   ChangeDlg->FromFileName->Text = FileList->FileName;
  282.   ChangeDlg->ToFileName->Text = "";
  283.  
  284.   if ((ChangeDlg->ShowModal() != mrCancel) &&
  285.      (ChangeDlg->ToFileName->Text != ""))
  286.  
  287.     ConfirmChange(ChangeDlg->Caption,
  288.                   ChangeDlg->FromFileName->Text,
  289.                   ChangeDlg->ToFileName->Text);
  290.  
  291. }
  292.  
  293. void __fastcall TFormMain::FileListDblClick(TObject *Sender)
  294. {
  295.   Open1Click(Sender);
  296. }
  297. //---------------------------------------------------------------------
  298.